<template>
	<view class="main-box">
		<view class="top-bg"></view>
		<view class="white-border-box">
			<view class="flex-box padding-box" @click="tapLoginClick()">
				<u-avatar size="50" :src="src" shape="circle"></u-avatar>
				<view class="title-view" v-if="!isLogin">未登录</view>
				<view class="title-view" v-if="isLogin">欢迎回来</view>
			</view>
		</view>
		<view class="cell-box">
			<view class="cell-item" @click="applyClick()">
				<view class="left-item">
					<image src='../../../static/account/a_icon_1.png' mode=""></image>
					<view class="">申请记录</view>
				</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
			<!--  v-if="userInfo.isAdmin == 1" -->
			<view class="cell-item" @click="approvalClick()" v-if="userInfo.isAdmin == 1">
				<view class="left-item">
					<image src='../../../static/account/a_icon_1.png' mode=""></image>
					<view class="">审核中心</view>
				</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
			<view class="cell-item" @click="contactClick()">
				<view class="left-item">
					<image src='../../../static/account/a_icon_2.png' mode=""></image>
					<view class="">联系我们</view>
				</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
			<view class="cell-item" style="border-bottom-color: transparent;" @click="joinDocumentClick()">
				<view class="left-item">
					<image src='../../../static/account/a_icon_3.png' mode=""></image>
					<view class="">加盟手册</view>
				</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>
		<view class="white-border-box bottom-border-box">
			<view class="apply-title">加盟说明</view>
		</view>
		<view class="login-out" v-if="isLogin" @click="loginOut">退出登录</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				src: '',
				isLogin : false,
				userInfo: null,
			};
		},
		onLoad() {
			// uni.showModal({
			// 	title: "提示",
			// 	content: "您还未登录，请先登录",
			// 	cancelText: "暂不登录",
			// 	confirmText: "去登录",
			// 	success(res) {
			// 		if (res.cancel) {

			// 		}else if (res.confirm) {
			// 			uni.navigateTo({
			// 				url: '/pages/loginPage/loginPage'
			// 			})
			// 		}
			// 	}
			// })
			this.isLogin = getApp().globalData.isLogin;
			this.userInfo = getApp().globalData.userInfo;
		},
		onShow() {
			this.isLogin = getApp().globalData.isLogin;
			this.userInfo = getApp().globalData.userInfo;
		},
		methods: {
			tapLoginClick() {
				if (!getApp().globalData.isLogin) {
					// uni.showModal({
					// 	title: "提示",
					// 	content: "您还未登录，请先登录",
					// 	cancelText: "暂不登录",
					// 	confirmText: "去登录",
					// 	success(res) {
					// 		if (res.cancel) {
					// 			uni.switchTab({
					// 				url: '/pages/tabs/home/home'
					// 			})
					// 		}else if (res.confirm) {
					// 			uni.navigateTo({
					// 				url: '/pages/loginPage/loginPage'
					// 			})
					// 		}
					// 	}
					// })
					uni.navigateTo({
						url: '/pages/loginPage/loginPage'
					})
					return;
				}
			},
			applyClick() {
				if (!getApp().globalData.isLogin) {
					uni.navigateTo({
						url: '/pages/loginPage/loginPage'
					})
					return;
				}
				console.log(1111111111111);
				uni.navigateTo({
					url: '/pages/applyHistory/applyHistory'
				})
			},
			approvalClick() {
				uni.navigateTo({
					url: '/pages/approvalList/approvalList'
				})
			},
			contactClick() {
				if (!getApp().globalData.isLogin) {
					uni.navigateTo({
						url: '/pages/loginPage/loginPage'
					})
					return;
				}
				console.log(2222222222222);
			},
			joinDocumentClick() {
				if (!getApp().globalData.isLogin) {
					uni.navigateTo({
						url: '/pages/loginPage/loginPage'
					})
					return;
				}
				console.log(3333333333333);
			},
			loginOut() {
				let _this = this;
				uni.showModal({
					content: '确定退出？',
					success(res) {
						if (res.confirm) {
							uni.setStorageSync('token', '');
							uni.setStorageSync('userInfo', null);
							getApp().globalData.isLogin = false
							getApp().globalData.userInfo = null
							_this.userInfo = null;
							_this.isLogin = false;
							uni.showToast({
								title: "退出登录"
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #f2f4f6;
	}
	.main-box {
		position: relative;
		padding-top: 10px;
		.top-bg {
			position: absolute;
			top: -20px;
			left: 0;
			right: 0;
			height: 300px;
			clip-path: ellipse(100% 50% at 50% 10%);
			background: $theme-color;
			z-index: -1;
		}
		.white-border-box {
			// background-color: white;
			margin: 10px 12px;
			margin-top: 30px;
			border-radius: 5px;
			min-height: 80px;
			padding: 10px;
			margin-bottom: 30px;
			// box-shadow: 0 0 2px 1px rgba(0, 0, 0, .1);
			color: white;
		}
		.bottom-border-box {
			background-color: white;
			color: #000;
			margin: 10px 12px;
		}
		.padding-box {
			padding: 16px 10px;
			box-sizing: border-box; 
		}
		.flex-box {
			display: flex;
			align-items: center;
			gap: 16px;
		}
		.title-view {
			font-size: 16px;
			font-weight: bold;
		}
		.cell-box {
			background-color: white;
			margin: 0px 12px;
			margin-top: 16px;
			border-radius: 5px;
			min-height: 80px;
			padding: 0 10px;
			// box-shadow: 0 0 4px 1px rgba(0, 0, 0, 0.05);
			.cell-item{
				height: 54px;
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-bottom: 1px solid rgba(0, 0, 0, .1);
				.left-item  {
					display: flex;
					align-items: center;
					gap: 10px;
					image {
						width: 24px;
						height: 24px;
					}
				}
			}
		}
		.apply-title{
			line-height: 30px;
			text-align: center;
			font-weight: bold;
		}
		.login-out{
			margin: 12px;
			background-color: #f56c6c;
			color: #fff;
			height: 44px;
			line-height: 44px;
			text-align: center;
			border-radius: 8px;
		}
	}
</style>
